package com.aaa.javaweb.servlet;

import com.aaa.javaweb.dao.YDDao;
import com.aaa.javaweb.dao.YdclDao;
import com.aaa.javaweb.entity.RuzhuDetail;
import com.aaa.javaweb.entity.Ydcl;
import com.aaa.javaweb.until.LayTable;
import com.aaa.javaweb.until.TableLabe;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class YuDingController {

    @Autowired
    private YDDao ydDao;
    @Autowired
    private YdclDao ydclDao;


    @RequestMapping("yddetail")
    @ResponseBody
    public TableLabe yddetail(){
        Date date = new Date();
        SimpleDateFormat ss = new SimpleDateFormat("yyyy-MM-dd");
        String format = ss.format(date);
        List<Map> selall=ydDao.selAll(format);
        TableLabe tableLabe = new TableLabe(0,"",selall.size(),selall);
        return tableLabe;
    }
    @RequestMapping("yddetails")
    @ResponseBody
    public TableLabe yddetails(){
        Date date = new Date();
        SimpleDateFormat ss = new SimpleDateFormat("yyyy-MM-dd");
        String format = ss.format(date);
       List<Map> maps=ydDao.selectxfrz(format);
        TableLabe tableLabe = new TableLabe(0,"",maps.size(),maps);

        return tableLabe;
    }
    @RequestMapping("yddetailss")
    @ResponseBody
    public TableLabe yddetailss(){
        Date date = new Date();
        SimpleDateFormat ss = new SimpleDateFormat("yyyy-MM-dd");
        String format = ss.format(date);
        List<Map> maps=ydDao.selectxfrzs(format);
        TableLabe tableLabe = new TableLabe(0,"",maps.size(),maps);

        return tableLabe;
    }


    @RequestMapping("yycl")
    @ResponseBody
    public List<Map> yycl(Ydcl ydcl){
        List<Map> selkongxian = ydclDao.selkongxian(ydcl.getTname());
        //System.out.println(ydcl.getName());
        //System.out.println(selkongxian);
        return selkongxian;
    }

    @RequestMapping("yycladd")
    @ResponseBody
    public int  yycladd(RuzhuDetail ruzhuDetail){
        int updatesta = 0;

       // System.out.println(ruzhuDetail.getId());
        //处理订单，插入入住详情表里
            int i=ydclDao.addruzhu(ruzhuDetail);
        /**
         * 当我插入一条信息的时候，我们需要获取到最大的退房表里的最大的离开时间的那一条信息，然后和入住详情表相连，改掉它的入住详情状态.
         */
        //我们先获取到这个房间号的最大离开时间
        List<Map> updstatus= ydclDao.updruzhustatus(ruzhuDetail.getRoomcode());
        if (updstatus.size()>0){
            int i1 = Integer.parseInt(updstatus.get(0).get("id") + "");
            updatesta = ydclDao.updatesta(i1);
        }

        //查询一个人的订房数量

            //订房数量
            Map map=ydclDao.selcon(ruzhuDetail);
        System.out.println(map);

            if(i>0){
                int j=ydclDao.updroomstatus(ruzhuDetail.getRoomcode());
                /*int a = Integer.parseInt(map.get(0).get("a")+"");
                System.out.println(a);
                //一个订单的入住详情数量
                int b = Integer.parseInt(map.get(0).get("b")+"");*/
                if(map.get("count")==map.get("b")){
                    int jj=ydclDao.updroomorde(ruzhuDetail.getId());
                }
        }
        //修改房间状态i
            /*if(i>0){
                //改变订单里的房间状态
                *//*int j=ydclDao.updroomstatus(ruzhuDetail.getRoomcode());
                if(a==b){
                    //改变订单的状态
                    //int jj=ydclDao.updroomorde(ruzhuDetail.getId());
                }*//*
            }*/
            return updatesta;
    }


}
